export default {
  name: 'reporting',
  components: {
    Create: () => { return import('./create.vue'); },
    Edit: () => { return import('./edit.vue'); }
  },
  data() {
    return {
      dialog4CreateTitle: '新增',
      dialog4CreateVisible: false,
      dialog4EditTitle: '编辑',
      dialog4EditVisible: false,
      isDev: process.env.NODE_ENV == 'development',
      rFReportFormsId: null,//报表ID
      tableData: [],
      page: { current: 1, size: 10, total: 0 },
    }
  },
  methods: {
    test(txt) {
      alert(txt)
    },
    getList() {
      let ceid = this.$store.getters.getCEID(true);
      let arg = {
        companyEmplyoeeId: this.ceId,
        companyEmployeeId: ceid,
      };
      let page = {
        // current: this.current,
        // size: this.size,
        // total: this.total,
      }
      let args = Object.assign(arg, page)
      this.$api.getRFReportForms(args).then((res) => {
        if (res.data.code === 200) {
          this.formatData(res.data.data)
        }
        // this.page.current = res.data.page.current;
        // this.page.size = res.data.page.size;
        // this.page.total = res.data.page.total;
      }).catch((err) => {
        console.error(err)
      })
    },//获取初始化列表，配合后面的formatData使用
    formatData(resData) {
      // if (resData.length < 1) { return }
      this.tableData = resData.map((v, i) => {
        return {
          idx: i + 1,//序号
          addTime: this.$moment(v.addTime).format('YYYY-MM-DD hh:mm:ss'),

          cusName: v.name,//客户姓名
          cusId: v.qywX_UsersId,//客户id/企业微信客户ID
          companyName: v.companyName,
          // cusTel: '156665758789',//客户电话

          rFReportFormsId: v.rF_ReportForms_Id,//报表ID
          ceid: v.company_Emplyoee_Id,
          esid: v.eS_Company_Id,//企业微信ID

          // orderNumber: '订单ID',//订单ID
          // dingdianUserId: '顶点用户ID',//顶点用户ID

          title: v.title,
          state: v.checkState,//状态
        }
      })
    },

    close() {
      this.dialog4CreateVisible = false;
      this.dialog4CreateTitle = `新增`;
      this.dialog4EditVisible = false;
      this.getList();
    },
    readyCreate() {
      this.cusId = null;
      this.rFReportFormsId = null;
      this.dialog4CreateVisible = true;
    },
    updataCreateTitle(nickname) {
      this.dialog4CreateTitle = `新增:${nickname}`
    },
    ajaxObj4Edit(obj) {
      let p = Promise.resolve(
        (() => {
          this.dialog4EditTitle = `编辑：${obj.cusName}的${obj.rFReportFormsId}报备`;
          this.dialog4EditVisible = true
        })()
      )
      p.then((res) => {
        let args = {
          cusId: obj.cusId,
          esId: obj.esid,
          rfrId: obj.rFReportFormsId,
          rfTitle: obj.title,
          type: 2,//1：全量（有已添加标记）2：仅添加（合规用）//后端好像有约定传常数2
          // beginTime: '',//起始日期，不知所以的变量
          // endTime: '',//终止日期，不知所以的变量
        }
        this.$refs.edit.initGetRFDetails(args);

      })

    },

    submit() {
      this.$refs.create.submitNewRForms()
    },
    submitRF2examine(rfObj) {
      this.$confirm('提交该报备记录', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info',
      }).then((res) => {
        let arg = {
          rFReportFormsId: rfObj.rFReportFormsId,
          checkState: 1,//审核中
        }
        return this.$api.checkReportForms(arg)
      }).then((res) => {
        if (res.data.code === 200 && res.data.data > 0) {
          this.getList()
        } else {
          this.$message({
            type: 'error',
            message: '提交失败',
          })
        }
      }).catch((err) => {

      });
    },
    update() {
      this.$refs.edit.realTimeUpdataRfTitle().then((res) => {
        console.log(res)
        this.close()
      }).catch((err) => {
        console.log(err)
      })
    },
    deleteRF(rfObj) {
      this.$confirm('删除该记录', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'waring',
      }).then((res) => {
        let arg = {
          companyEmployeeId: this.$store.getters.getCEID(true),
          rFReportFormsId: rfObj.rFReportFormsId
        };
        return this.$api.deleteRF(arg)
      }).then((res) => {
        if (res.data.code === 200 && res.data.data > 0) {
          this.getList()
        } else {
          this.$message({
            type: 'error',
            message: '删除失败',
          })
        }
      }).catch((err) => {

      });
    },
  },
  mounted() {
    this.getList()
  }

}
